const spawn = require("cross-spawn");
const fs = require("fs-extra");
// 下载项目
exports.downloadProject = async function downloadProject() {
    await download("https://gitee.com:banshiweichen/yistatic#master", tempDir, { clone: true });
};

// 执行脚本
exports.runScript = function runScript(script) {
    const res = spawn.sync("node", [path.resolve(myConfig.cliDir, "scripts", script + ".js")], { stdio: "inherit" });
    process.exit(res.status);
};

// 执行初始化
exports.executeInit = async function executeInit() {
    fs.removeSync(tempDir);
    fs.ensureDirSync(tempDir);
    await downloadProject();
    fs.copySync(tempDir, initDir, { overwrite: true });
    fs.removeSync(tempDir);
    console.log("yistatic项目结构下载成功");
};

// 更新配置
exports.executeUpdateConfig = async function executeUpdateConfig() {
    fs.removeSync(tempDir);
    fs.ensureDirSync(tempDir);
    await downloadProject();
    fs.removeSync(path.resolve(initDir, ".yistatic"));
    fs.copySync(path.resolve(tempDir, ".yistatic"), path.resolve(initDir, ".yistatic"), { overwrite: true });
    fs.removeSync(tempDir);
    console.log("yistatic项目配置更新成功");
};
